﻿package cn.antscript.airCMS.display.component 
{
	import cn.antscript.airCMS.data.PageData;
	import cn.antscript.airCMS.data.singleData.AbstractData;
	import cn.antscript.airCMS.display.component.AbstractItemContainer;
	import cn.antscript.airCMS.display.component.btnbase.AbstractTypeIco;
	import cn.antscript.airCMS.display.component.btnbase.IcoBitmapdatas;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author antscript
	 */
	public class TypeContainer extends Sprite
	{
		private var _pageData:PageData;
		
		private var _textIco:AbstractTypeIco;
		private var _imgIco:AbstractTypeIco;
		private var _musicIco:AbstractTypeIco;
		private var _videoIco:AbstractTypeIco;
		private var _fileIco:AbstractTypeIco;
		
		public var typeStr:String;
		
		public var isEmpty:Array;
		public var typeArr:Array = ["文本", "图片", "音乐", "视频", "文件"];
		public var typeStrs:Array = ["textContainer", "imgContainer", "musicContainer", "videoContainer", "fileContainer"];
		
		public function TypeContainer() 
		{
			_textIco = new AbstractTypeIco(IcoBitmapdatas.TxtType, "文本");
			_textIco.x = 0;
			_textIco.y = 0;
			addChild(_textIco);
			_textIco.addEventListener(MouseEvent.CLICK, onClick);
			
			_imgIco = new AbstractTypeIco(IcoBitmapdatas.ImgType, "图片");
			_imgIco.x = 80;
			_imgIco.y = 0;
			addChild(_imgIco);
			_imgIco.addEventListener(MouseEvent.CLICK, onClick);
			
			_musicIco = new AbstractTypeIco(IcoBitmapdatas.MusicType, "音乐");
			_musicIco.x = 160;
			_musicIco.y = 0;
			addChild(_musicIco);
			_musicIco.addEventListener(MouseEvent.CLICK, onClick);
			
			_videoIco = new AbstractTypeIco(IcoBitmapdatas.VideoType, "视频");
			_videoIco.x = 240;
			_videoIco.y = 0;
			addChild(_videoIco);
			_videoIco.addEventListener(MouseEvent.CLICK, onClick);
			
			_fileIco = new AbstractTypeIco(IcoBitmapdatas.FileType, "文件");
			_fileIco.x = 320;
			_fileIco.y = 0;
			addChild(_fileIco);
			_fileIco.addEventListener(MouseEvent.CLICK, onClick);
			
			
		}
		
		private function onClick(e:MouseEvent):void 
		{
			switch(e.target) {
				case _textIco:
				typeStr = "textContainer";
				break;
				case _imgIco:
				typeStr = "imgContainer";
				break;
				case _musicIco:
				typeStr = "musicContainer";
				break;
				case _videoIco:
				typeStr = "videoContainer";
				break;
				case _fileIco:
				typeStr = "fileContainer";
				break;
				default:
				break;
			}
		}
		
		public function show(pageData:Object):void {
			
			isEmpty = [];
			
			_pageData = pageData as PageData;
			
			if (_pageData.textContainer.length > 0) {
				_textIco.mouseEnabled = true;
				_textIco.alpha = 1;
				isEmpty[0] = false;
			}
			else {
				_textIco.mouseEnabled = false;
				_textIco.alpha = 0.2;
				isEmpty[0] = true;
			}
			
			if (_pageData.imgContainer.length > 0) {
				_imgIco.mouseEnabled = true;
				_imgIco.alpha = 1;
				isEmpty[1] = false;
			}
			else {
				_imgIco.mouseEnabled = false;
				_imgIco.alpha = 0.2;
				isEmpty[1] = true;
			}
			
			if (_pageData.musicContainer.length > 0) {
				_musicIco.mouseEnabled = true;
				_musicIco.alpha = 1;
				isEmpty[2] = false;
			}
			else {
				_musicIco.mouseEnabled = false;
				_musicIco.alpha = 0.2;
				isEmpty[2] = true;
			}
			
			if (_pageData.videoContainer.length > 0) {
				_videoIco.mouseEnabled = true;
				_videoIco.alpha = 1;
				isEmpty[3] = false;
			}
			else {
				_videoIco.mouseEnabled = false;
				_videoIco.alpha = 0.2;
				isEmpty[3] = true;
			}
			
			if (_pageData.fileContainer.length > 0) {
				_fileIco.mouseEnabled = true;
				_fileIco.alpha = 1;
				isEmpty[4] = false;
			}
			else {
				_fileIco.mouseEnabled = false;
				_fileIco.alpha = 0.2;
				isEmpty[4] = true;
			}
			
			
			
			
			//super.showBase();
		}
		
	}

}